﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace sy3_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // 1. 读取卡车属性输入
                int wheelCount = int.Parse(textBox1.Text);
                double weight = double.Parse(textBox2.Text);
                double load = double.Parse(textBox3.Text);
                double fuelConsump = double.Parse(textBox4.Text);

                // 2. 实例化Truck对象
                Truck truck = new Truck(wheelCount, weight, load, fuelConsump);

                // 3. 读取业务数据输入
                double goodsWeight = double.Parse(textBox5.Text);
                double distance = double.Parse(textBox6.Text);

                // 4. 检测超载并输出结果
                if (truck.IsOverload(goodsWeight))
                {
                    MessageBox.Show("对不起！卡车已超重，请卸下一些货物。", "超载提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    double fuel = truck.CalculateFuel(distance);
                    MessageBox.Show($"卡车正在行驶中。\n现已耗油{fuel}升！", "行驶提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("输入格式不合法，请输入有效数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
